/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2022. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */

#ifndef _EEP_DRV_H
#define _EEP_DRV_H
/*!
* @file eep_drv.h
* version: V2.1.5 EEP
* @brief This file provides EEP integration functions interface.
*
*/
#ifdef __cplusplus
extern "C" {
#endif

/* ===========================================  Includes  =========================================== */
#include <stdint.h>

/* ============================================  Define  ============================================ */
#define EEP_LIB_VERSION    "V2.1.5 EEP"
/* ===========================================  Typedef  ============================================ */
/*!< Callback typedef for eep module */
typedef void (*Eep_CallbackType)(void);

/*!
 * @brief IC type code.
 */
typedef enum
{
    EEP_AC78406 = 406U,
    EEP_AC78036 = 36U,
}Eep_IcType;

/*!
 * @brief EEP operate status.
 */
typedef enum
{
    EEP_SUCCESS         = 0U,   /*!< EEP operate successfully */
    EEP_STATU_ERROR     = 1U,   /*!< EEP operate status error which can check FLASH status register */
    EEP_PARA_ERROR      = 2U,   /*!< EEP input parameter error */
    EEP_TIMEOUT         = 3U,   /*!< EEP operate timeout when unlock FLASH */
    EEP_BUSY            = 4U,   /*!< EEP operate busy when FLASH command not finished */
    EEP_OTHER_ERROR     = 40U,  /*!< EEP other error, normally this will not occur */
}Eep_StatusType;
/*
    EEP size        RAM size        Flash size
    4096 byte       =EEP size       64KB
    2048 byte       =EEP size       32KB
    1024 byte       =EEP size       16KB
    <=512 byte      =EEP size       8KB
*/
typedef struct
{
    uint16_t EepSize;           /*!< The size of EEP (byte) */
    uint32_t EepRamBaseAddr;    /*!< The base address of EEP RAM */
    uint32_t EepFlashBaseAddr;  /*!< The base address of EEP FLASH */
    uint32_t FlashPageSize;     /*!< The FLASH page size (byte) */
    uint32_t FlashMinProByte;   /*!< The FLASH min program byte */
    Eep_IcType IcType;       /*!< The IC type */
    Eep_CallbackType CallbackType;    /*!< Call back function */
}Eep_ConfigType;
/*
    Main version
    Sub version
    Rev version
    Year of the current lib version released
    Year of the current lib version released
    Month of the current lib version released
    Date of the current lib version released
    Code branch
*/
typedef struct
{
    uint32_t Main;
    uint32_t Sub;
    uint32_t Rev;
    uint32_t Year;
    uint32_t Month;
    uint32_t Day;
}Eep_VersionType;
/* ====================================  Functions declaration  ===================================== */
/*!
 * @brief EEP initialize
 *
 * @param[in] config: EEP parameter struct
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_Init(const Eep_ConfigType *Config);

/*!
 * @brief EEP Write
 *
 * @param[in] addr: EEP address
 * @param[in] data: data buffer pointer
 * @param[in] size: the size of write data(uint is byte)
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_Write(uint32_t Addr, const uint8_t *Data, uint16_t Size);

/*!
 * @brief EEP read
 *
 * @param[in] addr: EEP read address
 * @param[in] data: Point to the buffer ready to read the data from EEP
 * @param[in] size: the number of read data(uint is byte)
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_Read(uint32_t Addr, uint8_t *Data, uint16_t Size);

/*!
 * @brief erase all EEP space
 *
 * @param[in] none
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_Erase(void);

/*!
 * @brief Get EEP lib version
 *
 * @param[in] EEP version struct
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_GetVersion(Eep_VersionType *Version);

/*!
 * @brief Reload flash data to eeprom
 *
 * @param[in] none
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_Refresh(void);

/*!
 * @brief Check EEPROM current busy status
 *
 * @param[in] none
 * @return EEP current status busy or idle
 */
Eep_StatusType Eep_Hal_CheckBusy(void);

#ifdef __cplusplus
}
#endif

#endif /* _EEP_DRV_H */

/* =============================================  EOF  ============================================== */
